package 贪心算法.买股票的最佳时机2;

/**
 * @author: wh(1835734390 @ qq.com)
 * @date: 2023/2/2 12:18
 * @description:
 * @version:
 */
public class Solution {
    public static void main(String[] args) {
        int[] array = {7,6,4,3,1};
        System.out.println(maxProfit(array));
    }

    //贪心算法 能赚钱赶快赚
    public static int maxProfit(int[] prices) {
        if (prices.length < 2){
            return 0;
        }
        int count = 0;
        for (int i = 1; i < prices.length; i++) {
            if (prices[i] > prices[i-1]){
                count += prices[i]-prices[i-1];
            }
        }
        return count;
    }
}
